﻿/**
 * 라디오 버튼의 인스턴스가 생성될때 
 * 라디오 버튼의 라디오그룹네임 변경할때
 */
package com.vinyl.controls
{
	public class RadioGroupManager
	{
		private static var _singleton:RadioGroupManager;
		private var radioGroupInfoList:Object = { };
		
		public function RadioGroupManager( singletonForce:SingletonForce )
		{
		}
		
		public static function getInstance():RadioGroupManager
		{
			if( !_singleton )
			{
				_singleton = new RadioGroupManager( new SingletonForce );
			}
			return _singleton;
		}
		
		/**
		 * groupName에 대한 RadioGroupInfo 정보를 얻오온다. 
		 */
		public function getRadioGroupInfo( groupName:String ):IRadioGroupInfo
		{
			var info:RadioGroupInfo = radioGroupInfoList[groupName] as RadioGroupInfo;
			if( !info )
			{
				info = new RadioGroupInfo( groupName );
				radioGroupInfoList[groupName] = info;
			}
			return new RadioGroupInfoProxy( info );
		}
		
		private function setRaidioGroup(): void
		{
		}	
	}
}

import com.vinyl.controls.IRadioGroupInfo;
import com.vinyl.controls.RadioGroupEvent;
import com.vinyl.controls.Button;
import com.vinyl.controls.RadioGroup;
import flash.events.Event;
import flash.events.EventDispatcher;

class SingletonForce {}

/**
 * 라디오그룹 관리
 */
class RadioGroupInfo extends EventDispatcher
{
	public var _groupName:String;
	public var _radioButtons:Array;
	public var radioGroup = new RadioGroup();
	
	public function RadioGroupInfo( groupName:String )
	{
		super();
		_groupName = groupName;
		
	}
	
	public function addRadioButton( button:Button )
	{
		if( !_radioButtons ) _radioButtons = new Array();
		_radioButtons.push( button );
		
		button.addEventListener( Button.EVENT_CHANGED, onButtonActionHandler );
	}
	
	public function removeRadioButton( button:Button )
	{
	}
	
	private function onButtonActionHandler( evt ): void
	{
		radioGroup.setSelected( evt.target );
	}
}

class RadioGroupInfoProxy extends EventDispatcher implements IRadioGroupInfo
{
	public var info:RadioGroupInfo;
	public function RadioGroupInfoProxy( info:RadioGroupInfo )
	{
		this.info = info;
	}
	
	public function addRadioButton( button:Button ):void
	{
		info.addRadioButton( button );
	}
	
	public function removeRadioButton( button:Button ):void
	{
		info.removeRadioButton( button )
	}
}




